# -*- coding: utf-8 -*-
# @File    : get_guid.py
# @Date    : 2021-12-25
# @Author  : Richard

import os
import time
import dmPython


def get_guid(ip, user, port, tena_id):

    try:
        sql = """select  ouguid from  OA9_5_0_GXBGT.FRAME_OU where FRAME_OU.OUCODE = '{0}';""".format(tena_id)
        # 这里是为了快速解决问题，建议使用特定方法使用字典方式获取密码同时加密
        if str(user).upper() == "WEBDOCUMENT":
            re_pwd = "!QAZxsw21qaz"
        elif str(user).upper() == "NOTICEV2":
            re_pwd = "!QAZxsw21qaz"
        elif str(user).upper() == "GOV_MEETING_ROOM_MANAGER":
            re_pwd = "GOV_MEETING_ROOM_MANAGER"
        elif str(user).upper() == "GOV_SYSTEM_MANAGEMENT":
            re_pwd = "GOV_SYSTEM_MANAGEMENT"
        elif str(user).upper() == "GOV_LEADERSHIP_AGENDA":
            re_pwd = "GOV_LEADERSHIP_AGENDA"
        elif str(user).upper() == "MP":
            re_pwd = "Dmdba@963"
        elif str(user).upper() == "PORTAL":
            re_pwd = "Dmdba@963"
        elif str(user).upper() == "OA9_5_0_GXBGT":
            re_pwd = "Dmdba@963"
        # 最高权限用户，有部分数据库节点的sysdba的密码有区别这里要做特殊处理
        elif str(user).upper() == "SYSDBA":
            ip_list = ["130.20.163.150", "130.20.164.17", "130.20.164.217", "130.20.163.199", "130.20.164.166",
                       "130.20.164.252", "130.20.164.113", "130.20.164.216", "130.20.164.5"]
            if ip in ip_list:
                re_pwd = "Dmdba@123"
            else:
                re_pwd = "Dmdba@963"
        conn = dmPython.connect(user=user, password=re_pwd, server=ip, port=port)
        cursor = conn.cursor()
        cursor.execute(sql)
        res = cursor.fetchall()
        # print(res)
        if res:
            return res
        conn.commit()
        cursor.close()
        conn.close()
    except Exception as  Err:
        print("ip_cnf----->{0}".format(ip))
        print("Execute sql statement error is:{0}".format(Err))

